import request from '@/utils/request'

// 发送聊天消息
export function sendChatMessage(data) {
  console.log('发送聊天消息 API 调用:', data)
  const requestData = {
    message: data.message,
    category: data.category,
    timestamp: new Date().getTime()
  }
  console.log('请求数据:', requestData)
  
  return request({
    url: '/chat/send',
    method: 'post',
    data: requestData
  }).then(response => {
    console.log('聊天 API 响应:', response)
    return response
  }).catch(error => {
    console.error('聊天 API 错误:', error)
    throw error
  })
}

// 获取聊天历史记录
export function getChatHistory(category, page = 1, size = 20) {
  return request({
    url: '/chat/history',
    method: 'get',
    params: {
      category: category,
      page: page,
      size: size
    }
  })
}

// 清空聊天记录
export function clearChatHistory(category) {
  return request({
    url: '/chat/clear',
    method: 'delete',
    data: {
      category: category
    }
  })
}

// 获取支持的分组列表
export function getChatCategories() {
  return request({
    url: '/chat/categories',
    method: 'get'
  })
}